<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right" class="top">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <el-row :gutter="20">
        <el-col :span="10">
          <el-input
            placeholder="请输入查询内容"
            v-model="queryinfo.query"
            size="small"
            class="input-with-select"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="query()"
            ></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-row>
        <el-table class="tabletop" :data="tableData" border style="width: 100%">
          <el-table-column type="index" label="序号"></el-table-column>
          <el-table-column
            prop="order_number"
            label="订单编号"
          ></el-table-column>
          <el-table-column
            prop="order_price"
            label="订单价格"
          ></el-table-column>
          <el-table-column label="是否付款">
            <template slot-scope="scope">
              <el-tag type="danger" v-show="scope.row.order_pay == 0"
                >未付款</el-tag
              >
              <el-tag v-show="scope.row.order_pay == 1">支付宝支付</el-tag>
              <el-tag type="success" v-show="scope.row.order_pay == 2"
                >微信支付</el-tag
              >
              <el-tag type="warning" v-show="scope.row.order_pay == 3"
                >银行卡支付</el-tag
              >
            </template>
          </el-table-column>
          <el-table-column prop="is_send" label="是否发货"></el-table-column>
          <el-table-column label="下单时间">
            <template slot-scope="scope">
              <div
                v-html="$options.filters.gltime(scope.row.create_time)"
              ></div>
            </template>
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="150">
            <template slot-scope="scope">
              <el-button
                type="primary"
                size="mini"
                icon="el-icon-edit"
                @click="goeait(scope.row)"
                >编辑</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </el-row>
      <el-row>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryinfo.pagenum"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="5"
          layout="total, sizes, prev, pager, next, jumper"
          :total="totalsize"
        ></el-pagination>
      </el-row>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "orders",
  data() {
    return {
      tableData: [],
      queryinfo: {
        query: "",
        pagenum: 1,
        pagesize: 5,
      },
      totalsize: 0,
    };
  },
  // 定义查询方法
  methods: {
    async query() {
      let rst = await this.$http.get("orders", this.queryinfo);
      console.log(rst);
      if (rst.meta.status == 200) {
        this.tableData = rst.data.goods;
        this.totalsize = rst.data.total;
      } else {
        this.$message.error("数据请求失败");
      }
    },
    async goeait(row) {
      console.log(row);
    },
    handleSizeChange(size) {
      this.queryinfo.pagesize = size;
      this.query();
    },
    handleCurrentChange(pagenum) {
      this.queryinfo.pagenum = pagenum;
      this.query();
    },
    
  },
  //过滤时间
  filters: {
    gltime: function (value) {
      const newdate = new Date(value);
      let str =
        newdate.getFullYear() +
        "-" +
        (newdate.getMonth() + 1) +
        "-" +
        newdate.getDate() +
        "<br/>" +
        newdate.getHours() +
        ":" +
        newdate.getMinutes() +
        ":" +
        newdate.getSeconds();
      return str;
    },
  },
  mounted() {
    // 调用查询方法
    this.query();
  },
};
</script>
<style scoped>
.top {
  margin-bottom: 20px;
}
</style>